package cn.core.tool.util;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

/**
 * 树
 */
@Data
@Accessors(chain = true)
public class CoreTree<T> implements Serializable {

  private static final long serialVersionUID = 1L;

  /**
   * 编号
   */
  protected String id;

  /**
   * 编号标识
   */
  protected String key;

  /**
   * 名称
   */
  protected String name;

  /**
   * 标识
   */
  protected String tkey;

  /**
   * 标题
   */
  protected String title;

  /**
   * 值
   */
  protected String value;

  /**
   * 父编号
   */
  protected String pid;

  /**
   * 是否有父节点
   */
  protected Boolean pnode;

  /**
   * 是否有子节点
   */
  protected Boolean cnode;

  /**
   * 节点是否展开
   */
  protected Boolean expand;

  /**
   * 节点是否选中
   */
  protected Boolean selected;

  /**
   * 节点是否勾选
   */
  protected Boolean checked;

  /**
   * 节点是否禁用
   */
  protected Boolean disabled;

  /**
   * 属性
   */
  protected T data;

  /**
   * 子节点
   */
  protected Collection<CoreTree<?>> children;

  public CoreTree() {
    super();
    this.pnode = false;
    this.cnode = false;
    this.expand = false;
    this.selected = false;
    this.checked = false;
    this.disabled = false;
    this.children = new ArrayList<CoreTree<?>>();
  }

  public CoreTree(T data) {
    this();
    this.data = data;
  }

  public CoreTree(Boolean expand, Boolean selected, Boolean checked, Boolean disabled) {
    super();
    this.pnode = false;
    this.cnode = false;
    this.expand = expand != null && expand ? true : false;
    this.selected = selected != null && selected ? true : false;
    this.checked = checked != null && checked ? true : false;
    this.disabled = disabled != null && disabled ? true : false;
    this.children = new ArrayList<CoreTree<?>>();
  }

  public CoreTree(T data, Boolean expand, Boolean selected, Boolean checked, Boolean disabled) {
    this(expand, selected, checked, disabled);
    this.data = data;
  }

}
